package com.hit.server.biz.controller;

import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hit.common.core.util.HitConvertUtils;
import com.hit.common.core.util.R;
import com.hit.common.log.annotation.SysLog;
import com.hit.server.api.dto.RobotWarningReadDTO;
import com.hit.server.api.entity.RobotWarningEntity;
import com.hit.server.api.dto.RobotWarningQueryDTO;
import com.hit.server.api.dto.RobotWarningUpdateDTO;
import com.hit.server.api.vo.RobotWarningVO;
import com.hit.server.api.service.RobotWarningService;
import com.hit.common.security.annotation.HasPermission;
import com.hit.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

/**
 * 机器人告警
 *
 * @author kehanjiang
 * @date 2025-04-14 16:24:49
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/robotWarning" )
@Tag(description = "robotWarning" , name = "机器人告警管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class RobotWarningController {

    private final  RobotWarningService robotWarningService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param dto 机器人告警
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    public R<Page<RobotWarningVO>> getRobotWarningPage(@ParameterObject Page page, @ParameterObject RobotWarningQueryDTO dto) {
	    dto = HitConvertUtils.emptyToNull(dto);
        return R.ok(robotWarningService.getRobotWarningPage(page, dto));
    }


    /**
     * 通过id查询机器人告警
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{id}" )
    public R<RobotWarningVO> getById(@PathVariable("id" ) Long id) {
        return R.ok(robotWarningService.getRobotWarningById(id));
    }

    /**
     * 修改机器人告警
     * @param dto 机器人告警
     * @return R
     */
    @Operation(summary = "修改机器人告警" , description = "修改机器人告警" )
    @SysLog("修改机器人告警" )
    @PutMapping
    public R<Boolean> updateById(@RequestBody RobotWarningUpdateDTO dto) {
        return R.ok(robotWarningService.updateRobotWarningById(dto));
    }

    /**
     * 告警处理-(已读)
     *
     * @param dto
     * @return
     */
    @Operation(summary = "告警处理-(已读)", description = "告警处理-(已读)")
    @SysLog("告警处理-(已读)")
    @PostMapping("/read")
    public R<Boolean> readWarning(@RequestBody RobotWarningReadDTO dto) {
        return R.ok(robotWarningService.readWarning(dto));
    }

    /**
     * 通过id删除机器人告警
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除机器人告警" , description = "通过id删除机器人告警" )
    @SysLog("通过id删除机器人告警" )
    @DeleteMapping
    public R<Boolean> removeById(@RequestBody Long[] ids) {
        return R.ok(robotWarningService.removeRobotWarningBatchByIds(CollUtil.toList(ids)));
    }
}